//ackage com.kaka.web_maven.controller;

import com.kaka.web_maven.dao.UsersDao;
import com.kaka.web_maven.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: web-maven
 * @className: ${PACKAGE_NAME}.${NAME}
 * @description: TODO
 * @author: 513 王老师(qq:292817678,tel&微信:18688753763)
 * @create: 2020-09-22 09:33
 **/
@WebServlet(name = "UsersServlet",urlPatterns = "/UsersServlet")
public class UsersServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 调用dao访问数据库
        UsersDao dao = new UsersDao();
        List<Users> list = new ArrayList<>();
        try {
            list = dao.getList();
        } catch (Exception e){
            e.printStackTrace();
        }

        System.out.println(list.size());
        // 将数据保存到页面做显示
        request.setAttribute("list",list);
        // 页面转发
        request.getRequestDispatcher("list.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}